<?php
namespace app\teacher\controller;

use app\teacher\controller\PublicController;
use app\common\model\TemplateAttrModel;

/**
 * 模板额外属性
 */
class TemplateAttrController extends PublicController
{
	public function add(){
		$param = $this->request->param();
		//halt($param);
		$name = TemplateAttrModel::where('template_id',$param['template_id'])->where('progress',$param['progress'])->value('name');
		$this->assign('name',$name);
		return $this->fetch();
	}

	public function toAdd(TemplateAttrModel $TemplateAttr){
		$param = $this->request->param();
		$name = TemplateAttrModel::where('template_id',$param['post']['template_id'])->where('progress',$param['post']['progress'])->value('name');
		if(empty($name)){
			$rs = $TemplateAttr->save($param['post']);
		}else{
			$rs = $name = TemplateAttrModel::where('template_id',$param['post']['template_id'])->where('progress',$param['post']['progress'])->update($param['post']);
		}
		if($rs){
			$this->success('操作成功','/teacher/template/look?id='.$param['post']['template_id'].'&progressid='.$param['progressid']);
		}else{
			$this->error('操作失败');
		}
	}
}
